package net.xuele.learn.executorPool;

import com.alibaba.fastjson.JSON;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Author: yubo
 * @date: 17:41 2020/7/3
 * @Description: 类描述
 */

public class SimpleExecutorTest {

    //0.普通线程池
    static ExecutorService executorService = Executors.newFixedThreadPool(8);
    public static void executeByOldPool(List<Person> personList) {
        personList.stream().forEach(p -> executorService.execute(() -> {
            System.out.println(JSON.toJSONString(p));
        }));
    }

    public static void main(String[] args) {
        //1.创建列表
        List<Person> personList = new ArrayList<>();
        personList.add(Person.builder().id(1).data("1s").build());
        personList.add(Person.builder().id(2).data("2s").build());
        personList.add(Person.builder().id(1).data("11s").build());
        personList.add(Person.builder().id(3).data("3s").build());
        personList.add(Person.builder().id(1).data("111s").build());
        personList.add(Person.builder().id(2).data("22s").build());
        personList.add(Person.builder().id(3).data("33s").build());
        personList.add(Person.builder().id(1).data("1111s").build());

        //2.使用普通线程池执行
        executeByOldPool(personList);
    }
}
